/-boot
/-docs
/-editor
/-files
/-files-old
/-imports
/-layout
/-shell
/-storage ...
/-storage/attached ...
/-storage/attached/api
/-storage/attached/dom
/-storage/attached/indexedDB ...
DetectStorage.ts
FileData.ts
LoadStorage.ts
MetadataData.ts
StorageAccess.ts
StorageDetect.ts
UpdateStorage.ts
functions.ts
/-storage/attached/localStorage
/-storage/attached/webSQL
/-tests
/-tests/files
/-tests/storage
TestCase.html
TestCase.ts
TestPage.css
TestPage.html
TestPage.ts
_sampleTests.ts
teapo-tests.html
teapo-tests.ts
/-typings
Dom.ts
TypeScriptService.ts
functions.ts
ko.ts
nteapo.html
persistence.api.ts
persistence.ts
shell.ts
teapo.html
teapo.ts
try.html
try.js
106
 
1
module teapo.storage.attached.indexedDB {
2
​
3
  export class StorageAccess implements attached.StorageAccess {
4
​
5
    constructor(private _db: IDBDatabase) {
6
    }
7
​
8
    update(
9
      byFullPath: PropertiesByFullPath,
10
      timestamp: number,
11
      callback: (error: Error) => void): void {
12
​
13
      var transaction = this._db.transaction(['files', 'metadata'], 'readwrite');
14
      transaction.onerror = (errorEvent) => callback(wrapErrorEvent(errorEvent, 'update: transaction'));
15
      var filesStore = transaction.objectStore('files');
16
      
17
      var outstandingRequests = 1;
18
​
19
      function oneError(errorEvent: ErrorEvent, moreDescription) {
20
        if (!outstandingRequests) return;
21
​
22
        outstandingRequests = 0;
23
        callback(wrapErrorEvent(errorEvent, moreDescription));
24
      }
25
​
26
      function oneCompleted() {
27
        if (!outstandingRequests) return;
28
​
29
        outstandingRequests--;
30
        callback(null);
31
      }
32
​
33
      for (var fullPath in byFullPath) if (byFullPath.hasOwnProperty(fullPath)) {↔}
72
​
73
      oneCompleted();
74
    }
75
​
76
    read(
77
      fullPath: string,
78
      callback: (error: Error, properties: { [property: string]: string; }) => void): void {
79
​
80
      var transaction = this._db.transaction('files');
81
      transaction.onerror = (errorEvent) => callback(wrapErrorEvent(errorEvent, 'read: transaction'), null);
82
      var filesStore = transaction.objectStore('files');
83
      var getRequest = filesStore.get(fullPath);
84
      getRequest.onerror = (errorEvent) => callback(wrapErrorEvent(errorEvent, 'read: get(' + fullPath +')'), null);
85
      getRequest.onsuccess = (event) => {
86
​
87
        var fileData: FileData = getRequest.result;
88
​
89
        callback(null, fileData.properties);        
90
        
91
      };
92
    }
93
​
94
    private _updateEditedUTC(now: number, transaction: IDBTransaction, callback: (errorEvent: ErrorEvent) => void) {
95
      var metadataStore = transaction.objectStore('metadata');
96
​
97
      var metadataData = { property: 'editedUTC', value: Date.now() };
98
      var putMetadata = metadataStore.put(metadataData);
99
      putMetadata.onerror = (errorEvent) => callback(errorEvent);
100
      putMetadata.onsuccess = (event) => callback(null);
72:21